package com.example.maze;

import tw.edu.tku.im.maze.*;

public class ConnectionInfo {
   //[ ---------- Constant ----------
   public static final int HE_IS_HOST  = 100,
                           HE_IS_CLIENT= 101;
   public static final int CONTINUE  = 100,
                           INTERRUPT = 101;
   //] ---------- Constant ----------
   
   //[ ---------- 使用者資料 ----------
   public static int state;
   public static String id;
   public static String name;
   public static int lv;
   public static int exp;
   public static int wins;
   public static int losses;
   public static int leaver;
   //] ---------- 使用者資料 ----------
   
   //] ---------- 連線設定 ----------
   public static int ticket;
   public static int identity            = HE_IS_CLIENT;
   public static int roomListupdateLoop  = INTERRUPT;
   public static int roomStatusupdateLoop= INTERRUPT;
   public static Object theUpdateService; 
   //] ---------- 連線設定 ----------
   
   //] ---------- 遊戲設定 ----------
   public static int    roomId;
   public static String roomName;
   public static int    mapLv;
   //] ---------- 遊戲設定 ----------
   
   // --------------------------------------------------
   private static void parse(LoginRep rep) {
      if(rep.getPlayerInfo() != null) {
         state = rep.getState();      
         id    = rep.getPlayerInfo().getUserID();
         name  = rep.getPlayerInfo().getName();
         lv    = rep.getPlayerInfo().getLv();
         exp   = rep.getPlayerInfo().getExp();
         wins  = rep.getPlayerInfo().getWins();
         losses= rep.getPlayerInfo().getLosses();
         leaver= rep.getPlayerInfo().getLeaver();
         ticket= rep.getPlayerInfo().getTicket();      
      }      
   }
   private static void parse(AddRoomRep rep) {
      roomId= rep.getRoomID();
   }
   public static void parseAndSaveInfo(RepPacket rep) {
      if(rep instanceof LoginRep) {
         parse((LoginRep)rep);         
      } else if(rep instanceof AddRoomRep) {
         parse((AddRoomRep)rep); 
      }
   }
}
